package com.liu.demo.aspect;

import com.liu.demo.exception.REnum;
import com.liu.demo.exception.RException;
import com.liu.demo.utils.RUtils;
import com.liu.demo.vo.R;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 统一异常处理
 */
@RestControllerAdvice
public class ExceptionHandle {

    @ExceptionHandler(value = Exception.class)
    public R handle(Exception e){
        if(e instanceof RException){
            RException rException = (RException) e;
            return RUtils.error(rException.getCode(),rException.getMessage());
        }

        return RUtils.error(REnum.UNKOWN_ERR);
    }
}
